{
 "cells": [
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# Numpy的ndarray的一维，二维的操作，常用属性，形状调整，与python list的互相转换",
   "id": "4f540378fb78042c"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "import numpy as np",
   "id": "498099623a3c326e"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "initial_id",
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 一维数组：\n",
    "# 1、列表转化为Numpy的一维数组\n",
    "list = [1, 2, 3, 4, 5, 6]\n",
    "one_array = np.array(list)\n",
    "print(one_array)\n",
    "print(type(one_array))\n",
    "# 2、range生成序列\n",
    "one_array_1 = np.array(range(1, 7))\n",
    "print(one_array_1)\n",
    "print(type(one_array_1))\n",
    "# 3、使用numpy自带的np.arange()生成数组\n",
    "one_array_2 = np.arange(1, 7)\n",
    "print(one_array_2)\n",
    "print(type(one_array_2))"
   ]
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": [
    "# 创建二维数组\n",
    "list = [[1, 2], [3, 4], [5, 6]]\n",
    "two_array = np.array(list)\n",
    "print(two_array)\n",
    "print(type(two_array))\n",
    "# 二维数组的属性\n",
    "print(two_array.ndim)\n",
    "print(two_array.shape)\n",
    "print(two_array.size)\n",
    "\n",
    "# np创建二维数组\n",
    "array_2 = np.array([[1, 2, 3], [4, 5, 6]])\n",
    "print(array_2.reshape(3, 2))\n",
    "print(array_2.reshape(1, 6))\n",
    "print(array_2.reshape(6, 1))\n",
    "# 数组转化为list\n",
    "list_2 = array_2.tolist()\n",
    "print(list_2)\n",
    "print(two_array)\n",
    "print(two_array.tolist())"
   ],
   "id": "c3e48f40950964f8"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
